package com.dal.module.account.paramcheck;

import java.util.Map;

import org.error.LoginErrorCode;

import com.dal.constant.DiscreteConstant;
import com.dal.constant.ParamKey;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.sojoys.artifact.exception.AbstractLogicModelException;
import com.sojoys.artifact.tools.ToolError;

/**
 * 抽象参数检查者
 * 封装必须参数检查方法
 * Created by fxf on 2017/6/22.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public abstract class AbstractParamChecker implements ParamChecker {

    @Override
    public void check(Controller controller, Map outParam) throws AbstractLogicModelException {
        String osName = controller.getPara(ParamKey.OS_NAME);
        ToolError.isAndTrue(LoginErrorCode.MISS_OS_TYPE,osName == null);
        outParam.put(ParamKey.OS_NAME, osName);
        outParam.put(ParamKey.OS_VERSION, controller.getPara(ParamKey.OS_VERSION,""));
        outParam.put(ParamKey.DEVICE_ID, controller.getPara(ParamKey.DEVICE_ID,""));
        outParam.put(ParamKey.DEVICE_TOKEN, controller.getPara(ParamKey.DEVICE_TOKEN,""));
        outParam.put(ParamKey.DEVICE_NAME, controller.getPara(ParamKey.DEVICE_NAME,""));
        outParam.put(ParamKey.CHANNEL_TAG, controller.getPara(ParamKey.CHANNEL_TAG,""));
        outParam.put(ParamKey.CHANNEL_APP_KEY, controller.getPara(ParamKey.CHANNEL_APP_KEY,""));
        outParam.put(ParamKey.SDK, controller.getPara(ParamKey.SDK,""));
        outParam.put(ParamKey.SDK_VERSION, controller.getPara(ParamKey.SDK_VERSION,""));
        outParam.put(ParamKey.SDK_VERSION, controller.getPara(ParamKey.SDK_VERSION,""));
        
        commonalityParamCheck(controller, outParam);
        
        if(DiscreteConstant.SYSTEM_TYPE_IOS.equals(osName)){	
            iosParamCheck(controller, outParam);
        }else{
            androidParamCheck(controller, outParam);
        }
        platformParamCheck(controller, outParam);
    }

    /**
     * 公共参数校验
     * @param controller 控制器
     * @param outParam 出参
     */
    private void commonalityParamCheck(Controller controller, Map outParam){
        //账号id
    	String accountId = controller.getPara(ParamKey.ACCOUNT_ID);
    	ToolError.isAndTrue(LoginErrorCode.MISS_ACCOUNT_ID,StrKit.isBlank(accountId));
    	outParam.put(ParamKey.ACCOUNT_ID, accountId);

    	//appId
    	String appId = controller.getPara(ParamKey.CHANNEL_APP_KEY);
    	ToolError.isAndTrue(LoginErrorCode.MISS_ACCOUNT_ID,StrKit.isBlank(appId));
    	outParam.put(ParamKey.CHANNEL_APP_KEY, appId);
    	
    	String channelId = controller.getPara(ParamKey.CHANNEL_TAG);
    	ToolError.isAndTrue(LoginErrorCode.PLATFORM_TYPE_IS_ERR,StrKit.isBlank(channelId));
    	outParam.put(ParamKey.CHANNEL_TAG, channelId);

    	//客服端版本号
    	String version = controller.getPara(ParamKey.CLIENT_VERSION);
    	ToolError.isAndTrue(LoginErrorCode.MISS_CLIENT_VERSION,version == null);
        outParam.put(ParamKey.CLIENT_VERSION, version);

    }

    /**
     * Android参数校验
     * @param controller 控制器
     * @param outParam 出参
     */
    private void androidParamCheck(Controller controller, Map outParam){

    }

    /**
     * ios参数校验
     * @param controller 控制器
     * @param outParam 出参
     */
    private void iosParamCheck(Controller controller, Map outParam){
    	
    }


}
